/********************************
 *版权所有 CopyRight(c) 快程乐码信息有限公司所有，未经授权，不得复制、转发
 */
package com.yjx.test.dozer.converterClazz;

import org.dozer.DozerConverter;

import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Date;

/************
 *@Author yejx
 *@version v1.0
 *@create 2020/6/29 13:53
 *@Description LocalDate 和 Date 转换器
 *
 */
public class LocalDateToDateConverter extends DozerConverter<LocalDate, Date> {

    public LocalDateToDateConverter() {
        super(LocalDate.class, Date.class);
    }

    /**
     * LocalDate 转换成    Date
     *
     * @param localDate
     * @param date
     * @return Date
     */
    @Override
    public Date convertTo(LocalDate localDate, Date date) {

        return Date.from(localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
    }


    /**
     * Date 转换成  LocalDate
     *
     * @param date
     * @param localDate
     * @return LocalDate
     */
    @Override
    public LocalDate convertFrom(Date date, LocalDate localDate) {
        return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
    }

}
